package com.example.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.dao.Import;
import com.example.dao.SearchGoods;
import com.example.entity.*;
import com.example.mapper.ComGoodsMapper;
import com.example.mapper.ComVenderMapper;
import com.example.mapper.VHnyyVenderMapper;
import com.example.service.VHnyyVenderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class VHnyyVenderServiceImpl implements VHnyyVenderService {
    @Autowired
    private VHnyyVenderMapper vHnyyVenderMapper;
    @Autowired
    private ComVenderMapper comVenderMapper;
    @Autowired
    private ComGoodsMapper comGoodsMapper;
    @Override
    public PageInfo<VHnyyVender> getParty(String comPartyId,String name,Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<VHnyyVender> basicInfos = vHnyyVenderMapper.getParty(comPartyId,name);
        return PageInfo.of(basicInfos);
    }

    @Override
    public PageInfo<VHnyyVenderGoodsQuery> getGoods(String comPartyId, SearchGoods searchGoods) {
        // 开启分页查询
        System.out.println("1111"+JSONObject.toJSONString(searchGoods));
        PageHelper.startPage(searchGoods.getPageNum(),searchGoods.getPageSize());
        List<VHnyyVenderGoodsQuery> basicInfos = vHnyyVenderMapper.getGoods(comPartyId,searchGoods);
        return PageInfo.of(basicInfos);
    }

    @Override
    public PageInfo<VHnyyVender> getClient(String comPartyId, String name,Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<VHnyyVender> basicInfos = vHnyyVenderMapper.getClient(comPartyId,name);
        return PageInfo.of(basicInfos);
    }

    @Override
    public PageInfo<SysClientPriceSets> getClientList(String comPartyId, String name,Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<SysClientPriceSets> basicInfos = vHnyyVenderMapper.getClientList(comPartyId,name);
        return PageInfo.of(basicInfos);
    }

    @Override
    public int addPolicy(HnyyPurRebateList hnyyPurRebateList) {
        return vHnyyVenderMapper.addPolicy(hnyyPurRebateList);
    }

    @Override
    public PageInfo<VHnyyVenderGoodsQuery> getCheck(Integer pageNum, Integer pageSize,String key,String comPartyId,String vender,String goodsDesc,String creater,String startDate,String endDate) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<VHnyyVenderGoodsQuery> basicInfos = vHnyyVenderMapper.getCheck(key,comPartyId,vender,goodsDesc,creater,startDate,endDate);
        return PageInfo.of(basicInfos);
    }

    @Override
    public HnyyPurRebateList getPolicy(String comGoodsId, String sysVenderGoodsRefId,String comPartyId) {
        return vHnyyVenderMapper.getPolicy(comGoodsId,sysVenderGoodsRefId,comPartyId);
    }

    @Override
    public int updatePolicy(HnyyPurRebateList hnyyPurRebateList) {
        return vHnyyVenderMapper.updatePolicy(hnyyPurRebateList);
    }

    @Override
    public List<VHnyyVender> getClientById(String comPartyId, String clientId) {
        return vHnyyVenderMapper.getClientById(comPartyId,clientId);
    }

    @Override
    public List<String> getVenderList(String comPartyId, List<String> ids) {
        System.out.println(comPartyId);
        List<SysClientPriceSets> venderList = vHnyyVenderMapper.getClientListByIds(comPartyId,ids);
        System.out.println("1231231231===>"+JSONObject.toJSONString(venderList));

        List<String> names = venderList.stream()
                .map(v -> v.getSysClientPriceSetsId() + "/" + v.getPriceSetName())
                .collect(Collectors.toList());

        return names;
    }

    @Override
    public VHnyyVenderGoodsQuery getImport(String comPartyId, Import importName) {
        System.out.println("importName"+JSONObject.toJSONString(importName));
        return vHnyyVenderMapper.getImport(comPartyId,importName);
    }

    @Override
    public int saveBatch(HnyyPurRebateList hnyyPurRebateList) {
        return vHnyyVenderMapper.insertTem(hnyyPurRebateList);
    }

    @Override
    public PageInfo<VHnyyPurRebateList> getTem(Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<VHnyyPurRebateList> basicInfos = vHnyyVenderMapper.getTem();
        return PageInfo.of(basicInfos);
    }

    @Override
    public int updateTem(String id, String opFlag) {
        return vHnyyVenderMapper.updateTem(id,opFlag);
    }

    @Override
    public PageInfo<ComVender> getVenderList(String comPartyId, String name,Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<ComVender> basicInfos = comVenderMapper.getVenderList(comPartyId,name);
        return PageInfo.of(basicInfos);
    }

    @Override
    public PageInfo<ComGoods> getGoodsList(String name, Integer pageNum, Integer pageSize) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<ComGoods> basicInfos = comGoodsMapper.getGoodsList(name);
        return PageInfo.of(basicInfos);
    }
}
